<?php
/**
 * licenses : MIT
 * creatTime: 2020/5/18
 * author : weblinuxgame
 * filename: TimestameTrait.php
 */

namespace App\Core\Traits\Database;

use Illuminate\Support\Carbon;

/**
 * Trait TimestampTrait
 * @package App\Core\Traits\Database
 */
trait TimestampTrait
{
    public function getCreatedAtAttribute()
    {
        $createdAt = $this->attributes['created_at'];
        if (empty($createdAt)) {
            return null;
        }
        $carbon = Carbon::make($createdAt);
        return $carbon ? $carbon->timestamp : null;
    }

    public function getUpdatedAtAttribute()
    {
        $updateAt = $this->attributes['updated_at'];
        if (empty($updateAt)) {
            return null;
        }
        $carbon = Carbon::make($updateAt);
        return $carbon ? $carbon->timestamp : null;
    }

}
